package com.xh.car.util;

import lombok.Data;

import java.util.List;

/**
 * @Author PangJunjie
 * @Date 2024/4/23/023
 */
@Data
public class R {
    private Integer code = 200;
    private String msg = "success";
    private Object data;
    private Long count;

    public static R ok() {
        return new R();
    }

    public static R ok(String msg) {
        R r = ok();
        r.setMsg(msg);
        return r;
    }

    public static R error() {
        R r = ok();
        r.setCode(500);
        r.setMsg("error");
        return r;
    }

    public static R error(Integer code) {
        R r = error();
        r.setCode(code);
        return r;
    }

    public static R error(String msg) {
        R r = error();
        r.setMsg(msg);
        return r;
    }

    public static R error(Integer code, String msg) {
        R r = error();
        r.setCode(code);
        r.setMsg(msg);
        return r;
    }

    public static R data(Object data) {
        R r = ok();
        r.setData(data);
        return r;
    }

    public static R page(long count, List<?> data) {
        R r = new R();
        r.setCode(0);
        r.setMsg("暂无数据");
        r.setCount(count);
        r.setData(data);
        return r;
    }

}
